package com.kichina.parking.controller.parking;

import com.kichina.parking.controller.base.BaseController;
import com.kichina.parking.controller.base.BaseResponse;
import com.kichina.parking.controller.base.BaseUpstreamResponse;
import com.kichina.parking.controller.base.RequestInfo;
import com.kichina.parking.controller.base.enums.BusinessType;
import com.kichina.parking.controller.parking.handler.CarBanDownControlHandler;
import com.kichina.parking.controller.parking.model.NoLicenceInParkRequest;
import com.kichina.parking.controller.parking.model.RemoteOpenRequest;
import com.kichina.parking.controller.parking.model.WhiteListSyncRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @author Surging
 * @version 1.0
 * @ClassName DebugController
 * @date 2022-09-07 15:10
 * @desc 调试停车管理系统的下行控制
 */
@RestController
@RequestMapping("/parking/control")
@Slf4j
public class CarBanDownControlController {

    private final CarBanDownControlHandler carBanDownControlHandler;

    public CarBanDownControlController(CarBanDownControlHandler carBanDownControlHandler) {
        this.carBanDownControlHandler = carBanDownControlHandler;
    }

    @PostMapping("/remoteOpen")
    @RequestInfo(model = "请求远程开闸", businessType = BusinessType.UPDATE)
    public BaseResponse remoteOpen(@RequestBody RemoteOpenRequest remoteOpenRequest) {
        log.info("http 接收APP云数据远程开闸" + remoteOpenRequest.toString());
        carBanDownControlHandler.remoteOpen(remoteOpenRequest);
        return BaseResponse.buildSuccess();
    }

    @PostMapping("/visitorIn")
    @RequestInfo(model = "无牌车入场", businessType = BusinessType.UPDATE)
    public BaseResponse visitorAdmission(@RequestBody NoLicenceInParkRequest noLicenceInParkRequest) {
        log.info("http 无牌车入场" + noLicenceInParkRequest.toString());
        carBanDownControlHandler.visitorAdmission(noLicenceInParkRequest);
        return BaseResponse.buildSuccess();
    }


    @PostMapping("/remoteWhite")
    @RequestInfo(model = "固定车注册与修改", businessType = BusinessType.UPDATE)
    public BaseResponse remoteWhiteList(@RequestBody WhiteListSyncRequest whiteListSyncRequest) throws ParseException {
        log.info("http 固定车注册与修改" + whiteListSyncRequest.toString());
        carBanDownControlHandler.remoteWhiteList(whiteListSyncRequest);
        return BaseResponse.buildSuccess();
    }
}
